using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PlayerController : MonoBehaviour
{
    private float speed=10;
    private void Start()
    {
        GameFacade.Instance.uIset.xiaoyouxitime = 30;
        InvokeRepeating(nameof(LoadCoin), 0, 1);
        Destroy(gameObject, 30);
    }
    private void Update()
    {
        transform.Translate(speed * Time.deltaTime * Vector3.right * Input.GetAxis("Horizontal"));
        if(transform.position.x> 18)
        {
            transform.position = new Vector3(18, 0, 0);
        }
        if (transform.position.x < -18)
        {
            transform.position = new Vector3(-18, 0, 0);
        }
        GameFacade.Instance.uIset.canvas.Find("Image").Find("Time").GetComponent<Text>().text = ((int)GameFacade.Instance.uIset.xiaoyouxitime).ToString();
    }
    void LoadCoin()
    {
        GameObject g = GameFacade.Instance.assetsFactory.LoadPrefab("PirateCoin");
        float x = Random.Range(-17f, 17f);
        g.transform.position = new Vector3(x, 0, 35);
    }
    
    private void FixedUpdate()
    {
       
            GameFacade.Instance.uIset.xiaoyouxitime -= 0.02f;
            if (GameFacade.Instance.uIset.xiaoyouxitime <= 0)
            {
              
                GameFacade.Instance.uIset.ButtonAll.gameObject.SetActive(true);
            }
        
       
    }
}
